﻿
Imports ADOEntityAMLO103
Partial Class Form_RptAmlo1_03
    Inherits System.Web.UI.Page
    Dim AmloEntity As AMLO103Entities
    Dim clsDateFormat As New clsDateFormat
    Dim clsMasterDropDown As clsMasterDropDown
    Dim strTempName As String = ""

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        AmloEntity = New AMLO103Entities
        clsMasterDropDown = New clsMasterDropDown
        Dim strRptSeq As String = Request.Item("RptSeq")
        Dim strRptIdx As String = Request.Item("RptIdx")
        'Dim strStatus As String = Request.Item("RPTStatus")

        Try
            'If strStatus = "" Then
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "window.close();", True)

            'Else
            If Not (strRptSeq = "") Then
                Dim sql = (From tblRRPT In AmloEntity.AMLO103 Join tblRRPTDEtail In AmloEntity.AMLODETAIL103 On tblRRPT.RPTSEQ Equals tblRRPTDEtail.RPTSEQ
                        Where tblRRPT.RPTSEQ = strRptSeq And (tblRRPTDEtail.RPTIDX = 1 Or tblRRPTDEtail.RPTIDX = strRptIdx)).ToList
                Dim countRow As Integer = sql.Count

                Dim qryRpt = (From tblRPT In AmloEntity.AMLO103 Where tblRPT.RPTSEQ = strRptSeq).ToList

                Dim qryRptDetail = (From tblRRPTDEtail In AmloEntity.AMLODETAIL103
                                    Where tblRRPTDEtail.RPTSEQ = strRptSeq And (tblRRPTDEtail.RPTIDX = 1 Or tblRRPTDEtail.RPTIDX = strRptIdx)).ToList
                setRptPart1(qryRpt, qryRptDetail)
                setRptPart2(qryRptDetail)

                setRptPart3(qryRpt)

                Response.Write("<script>")
                Response.Write("window.print()")
                Response.Write("</script>")


            End If
            'End If

        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub setRptPart1(ByVal RptMaster As IList(Of AMLO103), ByVal RptMasterCus As IList(Of AMLODETAIL103))
        Dim strTemp As String = ""
        Dim arrTemp As String() = Nothing

        'ทำการตัด HGBCode เป็นช่องๆ
        Try


            lblGHBCode1.Text = 0
            lblGHBCode2.Text = 3
            lblGHBCode3.Text = 3
            'ทำการตัด BranchCode เป็นช่องๆ
            strTemp = RptMaster(0).BRANCHCODE
            'branchCode1.Text = subStringText(RptMaster(0).BRANCHCODE, 1)
            'branchCode2.Text = subStringText(RptMaster(0).BRANCHCODE, 2)
            branchCode3.Text = subStringText(RptMaster(0).BRANCHCODE, 1)
            branchCode4.Text = subStringText(RptMaster(0).BRANCHCODE, 2)
            branchCode5.Text = subStringText(RptMaster(0).BRANCHCODE, 3)
            'ทำการตัด lblYear เป็นช่องๆ
            strTemp = RptMaster(0).RPTYEAR
            lblYear1.Text = subStringText(RptMaster(0).RPTYEAR, 1)
            lblYear2.Text = subStringText(RptMaster(0).RPTYEAR, 2)
            'ทำการใส่ค่า rptNo
            lblRptNo.Text = RptMaster(0).RPTNO

            'ทำการ set ค่า RptRev
            If (RptMaster(0).RPTREV = 0) Then
                lblRev0.Text = "x"
                lblRev1.Text = ""
                lblRevOther.Text = "0"
            Else
                lblRev0.Text = ""
                lblRev1.Text = "x"
                lblRevOther.Text = RptMaster(0).RPTREV
            End If


            'เป็นการ set ค่า RPTDate
            lblRptDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, RptMaster(0).RPTDATE)




            'เป็นการ set uniqueID
            Dim cusToTran = (RptMasterCus.Where(Function(t) t.RPTIDX = 1)).ToList

            lblUniqueID1.Text = subStringText(cusToTran(0).UNIQUEID, 1)
            lblUniqueID2.Text = subStringText(cusToTran(0).UNIQUEID, 2)
            lblUniqueID3.Text = subStringText(cusToTran(0).UNIQUEID, 3)
            lblUniqueID4.Text = subStringText(cusToTran(0).UNIQUEID, 4)
            lblUniqueID5.Text = subStringText(cusToTran(0).UNIQUEID, 5)
            lblUniqueID6.Text = subStringText(cusToTran(0).UNIQUEID, 6)
            lblUniqueID7.Text = subStringText(cusToTran(0).UNIQUEID, 7)
            lblUniqueID8.Text = subStringText(cusToTran(0).UNIQUEID, 8)
            lblUniqueID9.Text = subStringText(cusToTran(0).UNIQUEID, 9)
            lblUniqueID10.Text = subStringText(cusToTran(0).UNIQUEID, 10)
            lblUniqueID11.Text = subStringText(cusToTran(0).UNIQUEID, 11)
            lblUniqueID12.Text = subStringText(cusToTran(0).UNIQUEID, 12)
            lblUniqueID13.Text = subStringText(cusToTran(0).UNIQUEID, 13)

            If (cusToTran(0).RPTIDXTYPE = 1) Then
                lblRptIdxType1.Text = "x"
            ElseIf (cusToTran(0).RPTIDXTYPE = 2) Then
                lblRptIdxType2.Text = "x"
            End If

            'เป็นการ  set name
            Try
                'If (cusToTran(0).MIDNAME = "-") Then
                '    lblFullName.Text = cusToTran(0).FIRSTNAME & " " & cusToTran(0).LASTNAME
                'Else
                '    lblFullName.Text = cusToTran(0).FIRSTNAME & " " & cusToTran(0).MIDNAME & " " & cusToTran(0).LASTNAME
                'End If


                strTempName = ""
                If Not (cusToTran(0).PREFIX = "-" Or cusToTran(0).PREFIX = Nothing) Then
                    If (strTempName = "") Then
                        strTempName = strTempName + cusToTran(0).PREFIX
                    Else
                        strTempName = strTempName + " " + cusToTran(0).PREFIX
                    End If
                End If

                If Not (cusToTran(0).FIRSTNAME = "-" Or cusToTran(0).FIRSTNAME = "") Then
                    If (strTempName = "") Then
                        strTempName = strTempName + cusToTran(0).FIRSTNAME
                    Else
                        strTempName = strTempName + " " + cusToTran(0).FIRSTNAME
                    End If
                End If

                If Not (cusToTran(0).MIDNAME = "-" Or cusToTran(0).MIDNAME = "") Then
                    If (strTempName = "") Then
                        strTempName = strTempName + cusToTran(0).MIDNAME
                    Else
                        strTempName = strTempName + " " + cusToTran(0).MIDNAME
                    End If
                End If

                If Not (cusToTran(0).LASTNAME = "-" Or cusToTran(0).LASTNAME = "") Then
                    If (strTempName = "") Then
                        strTempName = strTempName + cusToTran(0).LASTNAME
                    Else
                        strTempName = strTempName + " " + cusToTran(0).LASTNAME
                    End If
                End If
                lblFullName.Text = strTempName

            Catch ex As Exception
                lblFullName.Text = cusToTran(0).FIRSTNAME & " " & cusToTran(0).LASTNAME
            End Try


            'เป็นการ set formal 
            lblFormalAddr.Text = cusToTran(0).FORMALADDR
            lblFormalPhone.Text = cusToTran(0).FORMALPHONE
            lblFormalFax.Text = cusToTran(0).FORMALFAX

            'เป็นการ set occupation, work
            If (cusToTran(0).OCCUPATIONTYPE = Nothing) Then
                lblOccupationType.Text = ""
            ElseIf (cusToTran(0).OCCUPATIONTYPE = 99) Then
                lblOccupationType.Text = ""
                lblOccupationTypeOther.Text = cusToTran(0).OCCUPATIONTYPEOTHER
                If (cusToTran(0).OCCUPATIONTYPEOTHER.Length > 18) Then
                    lblOccupationTypeOther.Font.Size = FontSize.Small
                End If
            Else
                lblOccupationType.Text = clsMasterDropDown.getOfficeOcc_AMLO103(AmloEntity, cusToTran(0).OCCUPATIONTYPE)
            End If


            lblWorkAddr.Text = cusToTran(0).WORKADDR
            If (cusToTran(0).WORKADDR.Length > 37) Then
                lblWorkAddr.Font.Size = FontSize.Small
            End If

            lblWorkPhone.Text = cusToTran(0).WORKPHONE

            'เป็นการ set สถานที่ติดต่อสะดวก
            lblContactAddr.Text = cusToTran(0).CONTACTADDR
            lblContactPhone.Text = cusToTran(0).CONTACTPHONE
            lblContactFax.Text = cusToTran(0).CONTACTFAX

            'เป็นการ set type หลักฐาน
            Try
                If Not (cusToTran(0).CUSTIDTYPE Is Nothing) Then
                    If (CInt(cusToTran(0).CUSTIDTYPE).ToString = "1") Then
                        lblCustype1.Text = "x"
                    ElseIf (CInt(cusToTran(0).CUSTIDTYPE).ToString = "6") Then
                        lblCustype1.Text = "x"
                    ElseIf (CInt(cusToTran(0).CUSTIDTYPE).ToString = "3") Then
                        lblCusType2.Text = "x"
                    ElseIf (CInt(cusToTran(0).CUSTIDTYPE).ToString = "4") Then
                        lblCusType3.Text = "x"
                    ElseIf (CInt(cusToTran(0).CUSTIDTYPE).ToString = "99") Then
                        lblCusType4.Text = "x"
                        lblCusTypeOther.Text = cusToTran(0).CUSTIDTYPEOTHER
                    Else
                        lblCusType4.Text = "x"
                        lblCusTypeOther.Text = clsMasterDropDown.getTypeID_AMLO103(AmloEntity, cusToTran(0).CUSTIDTYPE)
                    End If
                End If
            Catch ex As Exception

            End Try


            lblCusId.Text = cusToTran(0).CUSTID
            lblEvby.Text = cusToTran(0).EVBY
            If (cusToTran(0).EVGENTEXT = Nothing) Then
                lblEvGen.Text = ""
            ElseIf (cusToTran(0).EVGENTEXT = "-") Then
                lblEvGen.Text = "-"
            Else
                Try
                    'lblEvGen.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, cusToTran(0).EVGEN)
                    lblEvGen.Text = clsDateFormat.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, cusToTran(0).EVGENTEXT)
                Catch ex As Exception

                End Try
            End If

            If (cusToTran(0).EVEXPIRETEXT = Nothing) Then
                lblEvExpire.Text = ""
            ElseIf (cusToTran(0).EVEXPIRETEXT = "-") Then
                lblEvExpire.Text = "-"
            Else
                Try
                    'lblEvExpire.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, cusToTran(0).EVEXPIRE)
                    lblEvExpire.Text = clsDateFormat.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, cusToTran(0).EVEXPIRETEXT)
                Catch ex As Exception

                End Try
            End If


        Catch ex As Exception

        End Try


    End Sub

    Private Sub setRptPart2(ByVal RptDetailCus As IList(Of AMLODETAIL103))
        Dim RptDetailCusWhere = RptDetailCus.Where(Function(t) t.RPTIDX <> 1)
        If Not (RptDetailCusWhere.Count = 0) Then


            If (RptDetailCusWhere(0).RPTIDXTYPE = 1) Then
                lblPart2_RptIdxType1.Text = "x"
            ElseIf (RptDetailCusWhere(0).RPTIDXTYPE = 2) Then
                lblPart2_RptIdxType2.Text = "x"
            ElseIf (RptDetailCusWhere(0).RPTIDXTYPE = 3) Then
                lblPart2_RptIdxType3.Text = "x"
            End If

            lblPart2_UniqueId1.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 1)
            lblPart2_UniqueId2.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 2)
            lblPart2_UniqueId3.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 3)
            lblPart2_UniqueId4.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 4)
            lblPart2_UniqueId5.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 5)
            lblPart2_UniqueId6.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 6)
            lblPart2_UniqueId7.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 7)
            lblPart2_UniqueId8.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 8)
            lblPart2_UniqueId9.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 9)
            lblPart2_UniqueId10.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 10)
            lblPart2_UniqueId11.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 11)
            lblPart2_UniqueId12.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 12)
            lblPart2_UniqueId13.Text = subStringText(RptDetailCusWhere(0).UNIQUEID, 13)

            Try
                If (RptDetailCusWhere(0).MIDNAME = "-") Then
                    lblPart2_FullName.Text = RptDetailCusWhere(0).FIRSTNAME & " " & RptDetailCusWhere(0).LASTNAME
                Else
                    lblPart2_FullName.Text = RptDetailCusWhere(0).FIRSTNAME & " " & RptDetailCusWhere(0).MIDNAME & " " & RptDetailCusWhere(0).LASTNAME
                End If
            Catch ex As Exception
                lblPart2_FullName.Text = RptDetailCusWhere(0).FIRSTNAME & " " & RptDetailCusWhere(0).LASTNAME
            End Try


            lblPart2_FormalAddr.Text = RptDetailCusWhere(0).FORMALADDR
            If (RptDetailCusWhere(0).FORMALADDR.Length > 50) Then
                lblPart2_FormalAddr.Text = RptDetailCusWhere(0).FORMALADDR.Substring(0, 48)
                lblPart2_FormalAddr0.Text = RptDetailCusWhere(0).FORMALADDR.Substring(48, (RptDetailCusWhere(0).FORMALADDR.Length) - 48)

            End If

            lblPart2_formalPhone.Text = RptDetailCusWhere(0).FORMALPHONE
            lblPart2_formalFax.Text = RptDetailCusWhere(0).FORMALFAX


            If (RptDetailCusWhere(0).OCCUPATIONTYPE = Nothing) Then
                lblPart2_OccupationType.Text = ""
            ElseIf (RptDetailCusWhere(0).OCCUPATIONTYPE = 99) Then
                lblPart2_OccupationType.Text = ""
                lblPart2_OccupationTypeOther.Text = RptDetailCusWhere(0).OCCUPATIONTYPEOTHER
                If (RptDetailCusWhere(0).OCCUPATIONTYPEOTHER.Length > 18) Then
                    lblPart2_OccupationTypeOther.Font.Size = FontSize.Small
                End If
            Else
                lblPart2_OccupationType.Text = clsMasterDropDown.getOfficeOcc_AMLO103(AmloEntity, RptDetailCusWhere(0).OCCUPATIONTYPE)
            End If



            lblpart2_WorkAddr.Text = RptDetailCusWhere(0).WORKADDR
            If (RptDetailCusWhere(0).WORKADDR.Length > 37) Then
                lblpart2_WorkAddr.Font.Size = FontSize.Small
            End If
            lblpart2_WorkPhone.Text = RptDetailCusWhere(0).WORKPHONE

            If (RptDetailCusWhere(0).BIZTYPE Is Nothing) Then
                If (RptDetailCusWhere(0).BIZTYPE = 99) Then
                    lblBizType.Text = ""
                    lblBizTypeOther.Text = RptDetailCusWhere(0).BIZTYPEOTHER
                Else
                    lblBizType.Text = clsMasterDropDown.getOfficeType_AMLO103(AmloEntity, RptDetailCusWhere(0).BIZTYPE)
                End If

            End If





            lblPart2_ContactAddr.Text = RptDetailCusWhere(0).CONTACTADDR
            lblPart2_ContactPhone.Text = RptDetailCusWhere(0).CONTACTPHONE
            lblPart2_ContactFax.Text = RptDetailCusWhere(0).CONTACTFAX


            'เป็นการ set type หลักฐาน
            Try
                If Not (RptDetailCusWhere(0).CUSTIDTYPE Is Nothing) Then
                    If (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "1") Then
                        lblPart2_CusType1.Text = "x"
                    ElseIf (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "6") Then
                        lblPart2_CusType1.Text = "x"
                    ElseIf (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "3") Then
                        lblPart2_CusType2.Text = "x"
                    ElseIf (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "4") Then
                        lblPart2_CusType3.Text = "x"
                    ElseIf (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "5") Then
                        lblPart2_CusType4.Text = "x"
                    ElseIf (CInt(RptDetailCusWhere(0).CUSTIDTYPE).ToString = "99") Then
                        lblPart2_CusType5.Text = "x"
                    Else
                        lblPart2_CusType5.Text = "x"
                        lblPart2_CusTypeOther.Text = clsMasterDropDown.getTypeID_AMLO103(AmloEntity, RptDetailCusWhere(0).CUSTIDTYPE)

                        'lblPart2_CusType4.Text = "x"
                        'lblPart2_CusTypeOther.Text = RptDetailCusWhere(0).CUSTIDTYPEOTHER
                    End If
                End If
            Catch ex As Exception

            End Try


            lblPart2_CusId.Text = RptDetailCusWhere(0).CUSTID
            lblPart2_Evby.Text = RptDetailCusWhere(0).EVBY


            If (RptDetailCusWhere(0).EVGENTEXT = Nothing) Then
                lblPart2_EvGen.Text = ""
            ElseIf (RptDetailCusWhere(0).EVGENTEXT = "-") Then
                lblPart2_EvGen.Text = "-"
            Else
                Try
                    'lblPart2_EvGen.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, RptDetailCusWhere(0).EVGEN)
                    lblPart2_EvGen.Text = clsDateFormat.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, RptDetailCusWhere(0).EVGENTEXT)
                Catch ex As Exception

                End Try

            End If

            If (RptDetailCusWhere(0).EVEXPIRETEXT = Nothing) Then
                lblPart2_EvExpire.Text = ""
            ElseIf (RptDetailCusWhere(0).EVEXPIRETEXT = "-") Then
                lblPart2_EvExpire.Text = "-"
            Else
                Try
                    'lblPart2_EvExpire.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, RptDetailCusWhere(0).EVEXPIRE)
                    lblPart2_EvExpire.Text = clsDateFormat.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, RptDetailCusWhere(0).EVEXPIRETEXT)
                Catch ex As Exception

                End Try
            End If


        End If
        RptDetailCusWhere = Nothing
    End Sub

    Private Sub setRptPart3(ByVal RptMaster As IList(Of AMLO103))
        Dim dteDateSpil As String() = Nothing
        Dim blnChkTotaShow As Boolean = True
        Dim testStr As String = ""
        Dim dte_date As Date = Nothing
        Try
            dteDateSpil = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, RptMaster(0).TRANSDATE).Split("/")
            dte_date = RptMaster(0).TRANSDATE
            testStr = dte_date.ToString("MMMM")

            lblTransDate_Day.Text = dteDateSpil(0)
            lblTransDate_Month.Text = testStr
            lblTransDate_Year.Text = dteDateSpil(2)
        Catch ex As Exception

        End Try

        Try
            If Not (RptMaster(0).TRANSTYPE Is Nothing) Then
                If (RptMaster(0).TRANSTYPE = 1) Then
                    lblTransType01.Text = "x"
                    lblTransType01_Other.Text = RptMaster(0).TRANSTYPEOTHER
                ElseIf (RptMaster(0).TRANSTYPE = 2) Then
                    lblTransType02.Text = "x"
                    lblTransType02_Other.Text = RptMaster(0).TRANSTYPEOTHER
                End If
            End If

        Catch ex As Exception

        End Try





        If Not (RptMaster(0).TRANSAMT Is Nothing) Then
            lblTransAmtTotal.Text = insertComma(RptMaster(0).TRANSAMT)
        End If

        If Not (RptMaster(0).CURRENCY = "บาท") Then
            lblCurrency.Text = RptMaster(0).CURRENCY
        End If

        lblTransAmtChar1.Text = RptMaster(0).TRANSAMTCHAR




        lblAccountNo1.Text = RptMaster(0).ACCOUNTNO
        lblAccountName.Text = RptMaster(0).ACCOUNTNAME

        strTempName = ""
        If Not (RptMaster(0).ACCPREFIX = "-" Or RptMaster(0).ACCPREFIX = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).ACCPREFIX
            Else
                strTempName = strTempName + " " + RptMaster(0).ACCPREFIX
            End If
        End If

        If Not (RptMaster(0).ACCFIRSTNAME = "-" Or RptMaster(0).ACCFIRSTNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).ACCFIRSTNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).ACCFIRSTNAME
            End If
        End If

        If Not (RptMaster(0).ACCMIDNAME = "-" Or RptMaster(0).ACCMIDNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).ACCMIDNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).ACCMIDNAME
            End If
        End If

        If Not (RptMaster(0).ACCLASTNAME = "-" Or RptMaster(0).ACCLASTNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).ACCLASTNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).ACCLASTNAME
            End If
        End If
        lblAccCusName.Text = strTempName


        lblAccountRefNo1.Text = RptMaster(0).ACCOUNTREF
        lblAccountRefName.Text = RptMaster(0).ACCOUNTREFNAME

        strTempName = ""
        If Not (RptMaster(0).REFPREFIX = "-" Or RptMaster(0).REFPREFIX = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).REFPREFIX
            Else
                strTempName = strTempName + " " + RptMaster(0).REFPREFIX
            End If
        End If

        If Not (RptMaster(0).REFFIRSTNAME = "-" Or RptMaster(0).REFFIRSTNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).REFFIRSTNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).REFFIRSTNAME
            End If
        End If

        If Not (RptMaster(0).REFMIDNAME = "-" Or RptMaster(0).REFMIDNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).REFMIDNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).REFMIDNAME
            End If
        End If

        If Not (RptMaster(0).REFLASTNAME = "-" Or RptMaster(0).REFLASTNAME = "") Then
            If (strTempName = "") Then
                strTempName = strTempName + RptMaster(0).REFLASTNAME
            Else
                strTempName = strTempName + " " + RptMaster(0).REFLASTNAME
            End If
        End If
        lblAccCusRefName.Text = strTempName


        If (RptMaster(0).REFERENCETYPE = Nothing) Then
            lblRelation.Text = ""
        ElseIf (RptMaster(0).REFERENCETYPE = 99) Then
            lblRelation.Text = ""
            lblRelation_Other.Text = RptMaster(0).REFERENCETYPEOTHER
        Else
            lblRelation.Text = clsMasterDropDown.getRelation_AMLO103(AmloEntity, RptMaster(0).REFERENCETYPE)
        End If

        'ส่วนของผู้ได้รับผลประโยชน์

        Try
            strTempName = ""
            If Not (RptMaster(0).GAINPREFIX = "-" Or RptMaster(0).GAINPREFIX = "") Then
                If (strTempName = "") Then
                    strTempName = strTempName + RptMaster(0).GAINPREFIX
                Else
                    strTempName = strTempName + " " + RptMaster(0).GAINPREFIX
                End If
            End If

            If Not (RptMaster(0).GAINFIRSTNAME = "-" Or RptMaster(0).GAINFIRSTNAME = "") Then
                If (strTempName = "") Then
                    strTempName = strTempName + RptMaster(0).GAINFIRSTNAME
                Else
                    strTempName = strTempName + " " + RptMaster(0).GAINFIRSTNAME
                End If
            End If

            If Not (RptMaster(0).GAINMIDNAME = "-" Or RptMaster(0).GAINMIDNAME = "") Then
                If (strTempName = "") Then
                    strTempName = strTempName + RptMaster(0).GAINMIDNAME
                Else
                    strTempName = strTempName + " " + RptMaster(0).GAINMIDNAME
                End If
            End If

            If Not (RptMaster(0).GAINLASTNAME = "-" Or RptMaster(0).GAINLASTNAME = "") Then
                If (strTempName = "") Then
                    strTempName = strTempName + RptMaster(0).GAINLASTNAME
                Else
                    strTempName = strTempName + " " + RptMaster(0).GAINLASTNAME
                End If
            End If
            lblGainFullName.Text = strTempName
        Catch ex As Exception
            Throw ex
        End Try


        If (RptMaster(0).OBJBIZ Is Nothing) Then
            lblObjNameOther.Text = ""
        ElseIf (RptMaster(0).OBJBIZ = 99) Then
            lblObjNameOther.Text = RptMaster(0).OBJBIZOTHER
        Else
            lblObjNameOther.Text = clsMasterDropDown.getObjTypeName_AMLO103(AmloEntity, RptMaster(0).OBJBIZ)
        End If

        lblDocRef1.Text = subStringText(RptMaster(0).DOCREF, 1)
        lblDocRef2.Text = subStringText(RptMaster(0).DOCREF, 2)
        lblDocRef3.Text = subStringText(RptMaster(0).DOCREF, 3)
        lblDocRef4.Text = subStringText(RptMaster(0).DOCREF, 4)
        lblDocRef5.Text = subStringText(RptMaster(0).DOCREF, 5)
        lblDocRef6.Text = subStringText(RptMaster(0).DOCREF, 6)
        lblDocRef7.Text = subStringText(RptMaster(0).DOCREF, 7)
        lblDocRef8.Text = subStringText(RptMaster(0).DOCREF, 8)
        lblDocRef9.Text = subStringText(RptMaster(0).DOCREF, 9)

        Try
            If (RptMaster(0).SAVEDATE Is Nothing) Then
                lblSaveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, RptMaster(0).SAVEDATE)
            End If

        Catch ex As Exception

        End Try

        lblReson.Text = RptMaster(0).RESON

    End Sub


    Private Function subStringText(ByVal strText As String, ByVal intPosition As Integer) As String
        Try
            Dim strPositionSub As String = ""
            Dim intTextLength As Int32 = 0
            If Not (strText = "") Then
                intTextLength = strText.Length
                If (intPosition < intTextLength) Then
                    strPositionSub = strText.Substring(intPosition - 1, 1)
                ElseIf (intPosition = intTextLength) Then
                    strPositionSub = strText.Substring(intPosition - 1)
                Else
                    strPositionSub = ""
                End If
            Else
                strPositionSub = ""
            End If

            Return strPositionSub
        Catch ex As Exception
            Throw ex
        End Try

    End Function

    Private Function subStringText(ByVal strText As String, ByVal intPosition As Integer, ByVal intLength As Integer) As String
        Try
            Dim strPositionSub As String = ""
            Dim intTextLength As Int32 = 0
            If Not (strText = "") Then
                intTextLength = strText.Length
                If (intPosition < intTextLength) Then
                    If (intLength = 0) Then
                        strPositionSub = strText.Substring(intPosition - 1, 1)
                    Else
                        Dim intSumLength As Integer = (intPosition - 1) + intLength
                        If (intTextLength = intSumLength) Then
                            strPositionSub = strText.Substring(intPosition - 1, intLength)
                        End If
                    End If

                ElseIf (intPosition = intTextLength) Then
                    strPositionSub = strText.Substring(intPosition - 1)
                Else
                    strPositionSub = ""
                End If
            Else
                strPositionSub = ""
            End If

            Return strPositionSub
        Catch ex As Exception
            Throw ex
        End Try

    End Function

    Private Function insertComma(ByVal strTransAmt As String) As String
        Dim dcmMoney As Decimal
        Try
            dcmMoney = strTransAmt
            strTransAmt = Decimal.Parse(strTransAmt).ToString("N2")
        Catch ex As Exception
            Throw ex
        End Try
        Return strTransAmt
    End Function

End Class
